import request from '@/utils/http';
import { jsonToUrlParam, getApiUrl } from '../../urlSearchParams';
import {
  type AnnouncementDto,
  type AnnouncementCreateInputDto,
  type AnnouncementUpdateInputDto,
  type AnnouncementListDto,
  type AnnouncementGetListInputDto
} from './type';
import type { PagedResultDto } from '../type';

// Api地址
enum API {
  DEFAULT_URL = 'api/basics/announcement',
  LIST_URL = 'api/basics/announcement/list'
}

// 列表接口
export const getListAsync = (input: AnnouncementGetListInputDto) => {
  const paramenter = jsonToUrlParam(input);
  const url = getApiUrl(API.LIST_URL, paramenter);
  return request.get<PagedResultDto<AnnouncementListDto>>(url);
};

// 详情接口
export const getAsync = (id: string) => request.get<AnnouncementDto>(`${API.DEFAULT_URL}/${id}`);

// 创建
export const createAsync = (input: AnnouncementCreateInputDto) =>
  request.post<AnnouncementDto, AnnouncementCreateInputDto>(API.DEFAULT_URL, input);

// 更新
export const updateAsync = (id: string, input: AnnouncementUpdateInputDto) =>
  request.put<AnnouncementDto>(`${API.DEFAULT_URL}/${id}`, input);

// 删除
export const deleteAsync = (id: string) => request.delete<boolean>(`${API.DEFAULT_URL}/${id}`);
